2020-2021 Sunseeker Telemetry and Lighting System
rtc_b_ex2_calendermodeLPM3.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
65 //******************************************************************************
66 #include "driverlib.h"
67 
68 volatile Calendar newTime;
69 
70 void main(void)
71 {
72  Calendar currentTime;
73 
74  WDT_A_hold(WDT_A_BASE);
75 
76  // Unlock backup system
77  while(BattBak_unlockBackupSubSystem(BAK_BATT_BASE));
78 
79  //Set P1.0 to output direction
80  GPIO_setAsOutputPin(
81  GPIO_PORT_P1,
82  GPIO_PIN0
83  );
84 
85  //Initialize LFXT1
86  UCS_turnOnLFXT1(UCS_XT1_DRIVE_3,
87  UCS_XCAP_3
88  );
89 
90  //Setup Current Time for Calendar
91  currentTime.Seconds = 0x00;
92  currentTime.Minutes = 0x26;
93  currentTime.Hours = 0x13;
94  currentTime.DayOfWeek = 0x03;
95  currentTime.DayOfMonth = 0x20;
96  currentTime.Month = 0x07;
97  currentTime.Year = 0x2011;
98 
99  //Initialize Calendar Mode of RTC
100  /*
101  * Base Address of the RTC_B
102  * Pass in current time, intialized above
103  * Use BCD as Calendar Register Format
104  */
105  RTC_B_initCalendar(RTC_B_BASE,
106  &currentTime,
107  RTC_B_FORMAT_BCD);
108 
109  //Setup Calendar Alarm for 5:00pm on the 5th day of the week.
110  //Note: Does not specify day of the week.
111  RTC_B_configureCalendarAlarmParam param = {0};
112  param.minutesAlarm = 0x00;
113  param.hoursAlarm = 0x17;
114  param.dayOfWeekAlarm = RTC_B_ALARMCONDITION_OFF;
115  param.dayOfMonthAlarm = 0x05;
116  RTC_B_configureCalendarAlarm(RTC_B_BASE, &param);
117 
118  //Specify an interrupt to assert every minute
119  RTC_B_setCalendarEvent(RTC_B_BASE,
120  RTC_B_CALENDAREVENT_MINUTECHANGE);
121 
122  //Enable interrupt for RTC Ready Status, which asserts when the RTC
123  //Calendar registers are ready to read.
124  //Also, enable interrupts for the Calendar alarm and Calendar event.
125  RTC_B_clearInterrupt(RTC_B_BASE,
126  RTCRDYIFG + RTCTEVIFG + RTCAIFG);
127  RTC_B_enableInterrupt(RTC_B_BASE,
128  RTCRDYIE + RTCTEVIE + RTCAIE);
129 
130  //Start RTC Clock
131  RTC_B_startClock(RTC_B_BASE);
132 
133  //Enter LPM3 mode with interrupts enabled
134  __bis_SR_register(LPM3_bits + GIE);
135  __no_operation();
136 }
137 
138 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
139 #pragma vector=RTC_VECTOR
140 __interrupt
141 #elif defined(__GNUC__)
142 __attribute__((interrupt(RTC_VECTOR)))
143 #endif
144 void RTC_B_ISR(void)
145 {
146  // Unlock backup system
147  while(BattBak_unlockBackupSubSystem(BAK_BATT_BASE));
148 
149  switch(__even_in_range(RTCIV,16))
150  {
151  case 0: break; //No interrupts
152  case 2: //RTCRDYIFG
153  //Toggle P1.0 every second
154  GPIO_toggleOutputOnPin(
155  GPIO_PORT_P1,
156  GPIO_PIN0);
157  break;
158  case 4: //RTCEVIFG
159  //Interrupts every minute
160  __no_operation();
161 
162  //Read out New Time a Minute Later BREAKPOINT HERE
163  newTime = RTC_B_getCalendarTime(RTC_B_BASE);
164  break;
165  case 6: //RTCAIFG
166  //Interrupts 5:00pm on 5th day of week
167  __no_operation();
168  break;
169  case 8: break; //RT0PSIFG
170  case 10: break; //RT1PSIFG
171  case 12: break; //Reserved
172  case 14: break; //Reserved
173  case 16: break; //Reserved
174  default: break;
175  }
176 }
MPU_initThreeSegmentsParam param
__no_operation()
void main(void)
void RTC_B_ISR(void)
volatile Calendar newTime